package mil.af.amc.adpetracker.dao.hibernate;

import mil.af.amc.adpetracker.dao.MaintenanceEntryDao;
import mil.af.amc.adpetracker.model.MaintenanceEntry;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

/**
 * Please fill in this javadoc
 *
 * @author TSgt Jason Ferguson
 */
@Service("maintenanceEntryDao")
public class HibernateMaintenanceEntryDao extends HibernateGenericDao<MaintenanceEntry> implements MaintenanceEntryDao {

    public HibernateMaintenanceEntryDao() {
        super(MaintenanceEntry.class);
    }

    public List<MaintenanceEntry> getBySerialNumber(final String serial) {

        return (List<MaintenanceEntry>) getHibernateTemplate().execute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {

                Criteria crit = session.createCriteria(MaintenanceEntry.class);
                crit.add(Restrictions.eq("serial", serial));
                return crit.list();

            }
        }

        );

    }
}
